package com.sand;

import io.jsonwebtoken.*;

import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.security.Key;
import java.util.*;

//生成指定长度字符串
public class AppJwtUtil {

    // TOKEN的有效期1小时（S）
    private static final int TOKEN_TIME_OUT = 3600;

    // 加密KEY
    private static final String TOKEN_ENCRY_KEY = RandomStringGenerator.generateRandomString(50);

    // 生产ID
    public static String getToken(Integer id){

        Map<String, Object> claimMaps = new HashMap<>();
        claimMaps.put("id",id);

        long currentTime = System.currentTimeMillis();

        return Jwts.builder()
                .signWith(SignatureAlgorithm.HS256, TOKEN_ENCRY_KEY)
                .claims(claimMaps)
                .expiration(new Date(currentTime + TOKEN_TIME_OUT * 1000))
                .compact();
    }



}
